package main;

/**
 *	@(#)Rank.java
 *
 *	The <code>Rank</code> class holds the ranking data
 *	for each player. These are the time played, the round
 *	and phase the player quit the game and the size of
 *	his zone of control at that point.
 *
 *	@author Grzegorz Kobiela
 *	@version 1.0 2008/5/18
 */
public final class Rank
implements Comparable<Rank>
{
	/** The player. */
	private game.Player player;

	/** The playing time. */
	private long time;

	/** The round the player quits. */
	private int round;

	/** The phase the player quits. */
	private int phase;

	/** The size of the player's ZOC. */
	private int size;

	/** The rank. */
	private int rank;

	/**
	 *	Creates a new <code>Rank</code> instance.
	 *	@param player the player
	 *	@param time the time
	 *	@param phase the phase
	 *	@param size the size
	 */
	public Rank(game.Player player, long time, int round, int phase, int size) {
		this.player = player;
		this.time = time;
		this.round = round;
		this.phase = phase;
		this.size = size;
	}

	/**
	 *	Returns the player.
	 *	@return the player
	 */
	public game.Player getPlayer() {
		return player;
	}

	/**
	 *	Returns the time.
	 *	@return the time
	 */
	public long getTime() {
		return time;
	}

	/**
	 *	Returns the phase.
	 *	@return the phase
	 */
	public int getPhase() {
		return phase;
	}

	/**
	 *	Returns the round.
	 *	@return the round
	 */
	public int getRound() {
		return round;
	}

	/**
	 *	Returns the size.
	 *	@return the size
	 */
	public int getSize() {
		return size;
	}

	/**
	 *	Returns the rank.
	 *	@return the rank
	 */
	public int getRank() {
		return rank;
	}

	/**
	 *	Sets the rank to the given value.
	 *	@param rank the new rank
	 */
	public void setRank(int rank) {
		this.rank = rank;
	}

	/**
	 *	Implementation of <code>Comparable</code> interface.
	 *	@param rank the rank to compare with
	 *	@return the result as integer (-1, 0, +1)
	 */
	public int compareTo(Rank rank) {
		if(time < rank.time) return +1;
		if(time > rank.time) return -1;
		if(!player.wins() && rank.player.wins()) return +1;
		if(!player.wins() && !rank.player.wins()) return 0;
		if(player.wins() && !rank.player.wins()) return -1;
		if(size < rank.size) return +1;
		if(size > rank.size) return -1;
		return 0;
	}
}